package com.cyf.config;

import com.cyf.constant.DataSourceConstant;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.sql.DataSource;

/**
 * @author cyf
 * @description
 * @create 2018-09-14 18:07
 **/
@Configuration
public class JdbcDataSourceConfig {

    @Bean(name = DataSourceConstant.JDBC_DATASOUCE)
    @Qualifier
    public DataSource dataSource(){
//        不要在生产环境中使用 DriverManagerDataSource，因为DriverManagerDataSource 没有连接池功能，会打开连接，相当耗费资源
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName(DataSourceConstant.DRIVER_CLASS_NAME);
        dataSource.setUrl(DataSourceConstant.JDBC_URL);
        dataSource.setUsername(DataSourceConstant.USER_NAME);
        dataSource.setPassword(DataSourceConstant.PASS_WORD);
        return dataSource;
    }

}
